#include<stdio.h>

rev(int a,int *b)
{
	int k,l,t,temp;

	t=a/2;

	for(k=0;k<t;k++)
	{
		temp=b[k];
		b[k]=b[a-k];
		b[a-k]=temp;
	}

	for(l=1;l!=a+1;l++)
	{
		printf(" %d",b[l]);
	}

}

count(int a,int *b)
{
	int f,j;
	int c=0;
	printf("enter the no. to count:");
	scanf(" %d",&f);

	for(j=0;j<a;j++)
	{
		if(b[j]==f)
			c+=1;
		

	}
	printf(" no. of %d is : %d\n",f,c);
}

pop(int a, int *b)
{
	int c;
	int d[a-1];
	int j,k;


	printf(" \n Enter the index value  \n OR Enter 111 to pop last element");
	scanf(" %d",&c);


	if(c<a)
	{
		for(j=c;j<a-1;j++)
		{
			b[j]=b[j+1];
		}

		printf("\n\nThe new list is:");

		for(k=0;k<a-1;k++)
		{
			printf(" %d ",b[k]);
		}

	}
	else if(c==111)
	{
		
		for(j=0;j<a-1;j++)
		{
			d[j]=b[j];
		}
		printf("\n\nThe new list is:");

		for(k=0;k<a-1;k++)
		{
			printf(" %d ",d[k]);
		}
	}
	else
	{
		printf("no such index value\n");
	}
	printf("\n");
}

indval(int a, int *b)
{
	int c;
	printf("\n\n enter the index value :");
	scanf(" %d",&c);

	if(c<=a)
	{
		printf("\n the value is : %d ",b[c]);
	}
	else
	{
		printf("the index is invailid");
	}
}


append(int d, int *b)
{
	int c,k;
	printf(" \n enter the value to append:");
	scanf(" %d",&c);

	for(k=0;k<d-1;k++)
	{
		printf(" %d",b[k]);
	}

	b[d]=c;
	printf(" %d",b[d]);
}

sort(int a, int *b)
{
	int i,j,temp;
	for(i=0;i<a-1;i++)
	{
		for(j=0;j<a-i;j++)
		{
			if(b[j]<b[j+1])
			{
				temp=b[j];
				b[j]=b[j+1];
				b[j+1]=temp;
			}
		}
	}

	printf("\n\n-- Sorted Series --");
	
	for(i=0;i<a;i++)
	{
		printf("\n \n \t %d",b[i]);
	}



}
insert(int a,int *b)
{
	int f,e,k;
	printf("enter the new value to insert");
	scanf(" %d",&f);
	

	printf("at the position: ");
	scanf(" %d",&e);

	if(e<a)
	{
		b[e]=f;	
		for(k=0;k!=a;k++)
		{
			printf(" %d ",b[k]);
		}
	}
	else
	{
		printf("no index valid");
	}


}

void main()
{
int a,c,d;
int i,*q;

	printf("enter the size of array:");
	scanf(" %d",&a);
	int b[a];
	printf(" \n enter the elemnts of array \n\n");
	for(i=0;i<a;i++)
	{
		printf(" enter :");
		scanf(" %d",&b[i]);
	}
	do
	{
		printf("Choose the operation[0 to quit]:");
		printf("\n1.Reverse \n 2.Count \n 3. Pop \n 4. Index \n 5.Append \n 6.Sort \n 7.Insert \nChoice: ");
		scanf(" %d",&c);
		switch(c)
		{
			case 1: rev(a,b);
				break;
			case 2: count(a,b);
				break;
			case 3: pop(a,b);
				break;
			case 4: indval(a,b);
				break;
			case 5: d=a+1; 
				append(d,b);
				break;
			case 6: sort(a,b);
				break;
			case 7: insert(a,b);
				break;
			case 0: break;
			default: printf("Wrong choice!!!\n"); break;
		}
	}
	while(c!=0);
}


